
//
//  TSLoginVC.m
//  tristana
//
//  Created by bug neo on 05/01/2021.
//  Copyright © 2021 李康. All rights reserved.
//

#import "TSLoginVC.h"

#import "UITextField+inputs.h"

#import "TSRegisterVC.h"
#import "TSToast.h"

#import "UserService.h"

@interface TSLoginVC ()
@property (weak, nonatomic) IBOutlet UITextField *phoneTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation TSLoginVC


#pragma mark - Public Method
+ (void)showLoginVC {
    TSLoginVC *vc = [TSLoginVC new];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    nav.navigationBarHidden = YES;
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:nav animated:YES completion:nil];
}
#pragma mark - Life Cycle
- (instancetype)init {
    self = [super init];
    if (self) {
        if (@available(iOS 8.0, *)) {
            self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        } else {
            self.modalPresentationStyle=UIModalPresentationCurrentContext;
        }
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (void)dealloc
{
    NSLog(@"%s",__func__);
}
#pragma mark - Data Query

#pragma mark - Notification

#pragma mark - UI

#pragma mark - Delegate

#pragma mark - Private Method
- (void)hide {
    [self.phoneTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
}
#pragma mark - Overwrite Method

#pragma mark - Event Response

- (IBAction)closeVC:(id)sender {
    [self hide];
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)register:(id)sender {
    [self hide];
    NSLog(@"去注册");
    TSRegisterVC *vc = [[TSRegisterVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)clickLogin:(id)sender {
    if (([self.phoneTextField.text isEqualToString:@"17900000000"] || [self.phoneTextField.text isEqualToString:@"17900000001"] || [self.phoneTextField.text isEqualToString:@"17900000002"]) && [self.passwordTextField.text isEqualToString:@"123456"]) {
        
        [TSToast toast:@"登录成功"];
        [self dismissViewControllerAnimated:YES completion:nil];
        
        UserBean *bean = [[UserBean alloc] init];
        bean.phone = self.phoneTextField.text;
        [UserService saveUserBean:bean];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"kloginsuccess" object:nil];
        
    }else {
        [TSToast toast:@"请输入正确的手机号和密码"];
    }
}
#pragma mark - Setter

#pragma mark - Getter
@end
